/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cratos.xxgram.platf.qrcode;

import com.cratos.xxgram.platf.base.BaseService;
import com.cratos.xxgram.platf.base.RetCodes;
import com.cratos.xxgram.platf.file.FileService;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import org.redkale.service.RetResult;
import org.redkale.util.Comment;

/**
 *
 * @author SquRab
 */
public class QrCodeService extends BaseService {

    @Comment("logo 图片地址")
    @Resource(name = "property.qrcode.logopath")
    private String imgpath;
 
    @Resource
    private FileService fileService;

    public RetResult encode(String text, String fileName) {
        try {
            String name = fileService.storeQrCodeImage(fileName, QRCodeUtil.encode(text, imgpath, true));
            return RetResult.success(name);
        } catch (Exception ex) {
            Logger.getLogger(QrCodeService.class.getName()).log(Level.SEVERE, null, ex);
            return RetCodes.retResult(RetCodes.RET_QRCODE_CREATE_FIAL);
        }
    }

}
